(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 11.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[     71195,       1525]
NotebookOptionsPosition[     68274,       1427]
NotebookOutlinePosition[     68736,       1446]
CellTagsIndexPosition[     68693,       1443]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["Project Euler 21-30", "Title",
 CellChangeTimes->{{3.82599534582302*^9, 3.82599534949002*^9}, {
  3.826344412413868*^9, 3.826344414059868*^9}},
 TextAlignment->Center],

Cell[CellGroupData[{

Cell["\[FilledSquare]21. Amicable numbers", "Subsubsection",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9}],

Cell["\<\
Let d(n) be defined as the sum of proper divisors of n (numbers less than n \
which divide evenly into n).
If d(a) = b and d(b) = a, where a \[NotEqual] b, then a and b are an amicable \
pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, \
55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, \
71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.\
\>", "Text",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{"range10000", " ", "=", " ", 
   RowBox[{"Range", "[", 
    RowBox[{"2", ",", "9999"}], "]"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"sumAmicable", " ", "=", " ", "0"}], ";"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"FindAmicable", "[", "num_", "]"}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", "amicable", "}"}], ",", "\n", 
     RowBox[{
      RowBox[{"amicable", " ", "=", " ", 
       RowBox[{
        RowBox[{"Most", "[", 
         RowBox[{"Divisors", "[", "num", "]"}], "]"}], "//", "Total"}]}], ";",
       "\n", 
      RowBox[{"If", "[", 
       RowBox[{
        RowBox[{
         RowBox[{
          RowBox[{"Total", "@", 
           RowBox[{"Most", "[", 
            RowBox[{"Divisors", "[", "amicable", "]"}], "]"}]}], "\[Equal]", 
          "num"}], " ", "&&", " ", 
         RowBox[{"num", "\[NotEqual]", " ", "amicable"}]}], ",", 
        RowBox[{
         RowBox[{"sumAmicable", " ", "=", " ", 
          RowBox[{"sumAmicable", "+", "num"}]}], ";"}]}], "]"}]}]}], "\n", 
    "]"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"Scan", "[", 
   RowBox[{
    RowBox[{
     RowBox[{"FindAmicable", "[", "#", "]"}], "&"}], "\n", ",", 
    "range10000"}], "]"}], ";"}], "\n", "sumAmicable"}], "Code",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}}]
}, Open  ]],

Cell[BoxData["31626"], "Output",
 CellChangeTimes->{
  3.826935153298431*^9, {3.826935235430643*^9, 3.826935258328933*^9}, {
   3.8269353339102564`*^9, 3.8269353651212564`*^9}, {3.8269359019272566`*^9, 
   3.826935923230426*^9}, 3.8269366067697725`*^9, 3.8269374218532734`*^9, {
   3.8269375384649334`*^9, 3.826937543107397*^9}, {3.82693762574366*^9, 
   3.826937629895075*^9}, {3.826937696998785*^9, 3.826937703897475*^9}, 
   3.826937818349919*^9, {3.8269379411491976`*^9, 3.826937950363119*^9}, 
   3.8274403744643445`*^9}],

Cell[CellGroupData[{

Cell["\[FilledSquare]22. Names scores", "Subsubsection",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}}],

Cell["\<\
Using p022_names.txt (right click and \[OpenCurlyQuote]Save Link/Target As...\
\[CloseCurlyQuote]), a 46K text file containing over five-thousand first \
names, begin by sorting it into alphabetical order. Then working out the \
alphabetical value for each name, multiply this value by its alphabetical \
position in the list to obtain a name score.
For example, when the list is sorted into alphabetical order, COLIN, which is \
worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN \
would obtain a score of 938 \[Times] 53 = 49714.
What is the total of all the name scores in the file?\
\>", "Text",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9}],

Cell[BoxData[{
 RowBox[{
  RowBox[{"names", " ", "=", " ", 
   RowBox[{
    RowBox[{"StringCases", "[", 
     RowBox[{
      RowBox[{
      "Import", "[", "\"\<D:/workspace/project-euler/p022_names.txt\>\"", 
       "]"}], ",", 
      RowBox[{"WordCharacter", ".."}]}], "]"}], "//", "Sort"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"Table", "[", 
   RowBox[{
    RowBox[{"i", "*", 
     RowBox[{"(", 
      RowBox[{
       RowBox[{
        RowBox[{"ToCharacterCode", "[", 
         RowBox[{
         "names", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], 
         "]"}], "-", "64"}], "//", "Total"}], ")"}]}], ",", 
    RowBox[{"{", 
     RowBox[{"i", ",", 
      RowBox[{"Length", "@", "names"}]}], "}"}]}], "]"}], "//", 
  "Total"}]}], "Code",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}}]
}, Open  ]],

Cell[BoxData["871198282"], "Output",
 CellChangeTimes->{{3.826943988902931*^9, 3.826944032968337*^9}, 
   3.827440379931657*^9}],

Cell[CellGroupData[{

Cell["\[FilledSquare]23. Non-abundant sums", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, 3.827440672900414*^9}],

Cell["\<\
A perfect number is a number for which the sum of its proper divisors is \
exactly equal to the number. For example, the sum of the proper divisors of \
28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
A number n is called deficient if the sum of its proper divisors is less than \
n and it is called abundant if this sum exceeds n.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest \
number that can be written as the sum of two abundant numbers is 24. By \
mathematical analysis, it can be shown that all integers greater than 28123 \
can be written as the sum of two abundant numbers. However, this upper limit \
cannot be reduced any further by analysis even though it is known that the \
greatest number that cannot be expressed as the sum of two abundant numbers \
is less than this limit.
Find the sum of all the positive integers which cannot be written as the sum \
of two abundant numbers.\
\>", "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, 3.827440672900414*^9}],

Cell[BoxData[""], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, 
   3.827440672901414*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]24. Lexicographic permutations", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, 3.827440672901414*^9}],

Cell["\<\
A permutation is an ordered arrangement of objects. For example, 3124 is one \
possible permutation of the digits 1, 2, 3 and 4. If all of the permutations \
are listed numerically or alphabetically, we call it lexicographic order. The \
lexicographic permutations of 0, 1 and 2 are:
012   021   102   120   201   210
What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, \
5, 6, 7, 8 and 9?\
\>", "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, 3.827440672901414*^9}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"Permutations", "[", 
   RowBox[{"{", 
    RowBox[{
    "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7",
      ",", "8", ",", "9"}], "}"}], "]"}], "\[LeftDoubleBracket]", "1000000", 
  "\[RightDoubleBracket]"}]], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "2", ",", "7", ",", "8", ",", "3", ",", "9", ",", "1", ",", "5", ",", "4", 
   ",", "6", ",", "0"}], "}"}]], "Output",
 CellChangeTimes->{{3.82744038016267*^9, 3.827440380381683*^9}, {
   3.8274404399310884`*^9, 3.827440472262938*^9}, 3.8274405115901875`*^9}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]25. 1000-digit Fibonacci number", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}}],

Cell["\<\
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn\[Minus]1 + Fn\[Minus]2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
    F1 = 1
    F2 = 1
    F3 = 2
    F4 = 3
    F5 = 5
    F6 = 8
    F7 = 13
    F8 = 21
    F9 = 34
    F10 = 55
    F11 = 89
    F12 = 144
The 12th term, F12, is the first term to contain three digits.
What is the index of the first term in the Fibonacci sequence to contain 1000 \
digits?\
\>", "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Fibonacci", "[", "4782", "]"}], "//", "IntegerDigits"}], "//", 
  "Length"}]], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}}],

Cell[BoxData["1000"], "Output",
 CellChangeTimes->{{3.827440844187211*^9, 3.8274409288380527`*^9}}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]26. Reciprocal cycles", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}, {
   3.827440966885229*^9, 3.8274409684953213`*^9}}],

Cell["\<\
A unit fraction contains 1 in the numerator. The decimal representation of \
the unit fractions with denominators 2 to 10 are given:
    1/2\t= \t0.5
    1/3\t= \t0.(3)
    1/4\t= \t0.25
    1/5\t= \t0.2
    1/6\t= \t0.1(6)
    1/7\t= \t0.(142857)
    1/8\t= \t0.125
    1/9\t= \t0.(1)
    1/10\t= \t0.1 
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be \
seen that 1/7 has a 6-digit recurring cycle.
Find the value of d < 1000 for which 1/d contains the longest recurring cycle \
in its decimal fraction part.\
\>", "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}, {
   3.827440974140644*^9, 3.827440983055154*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"$RecursionLimit", "=", "4096"}], ";", 
  RowBox[{
  "(*", "\:4ee5\:4e0b\:7a0b\:5e8f\:53ef\:80fd\:4f1a\:8d85\:51fa\:9ed8\:8ba4\
1024\:9012\:5f52\:6df1\:5ea6", "*)"}], "\n", 
  RowBox[{
   RowBox[{"LegthRecurring", "[", 
    RowBox[{"a_", ",", "b_"}], "]"}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       RowBox[{"result", " ", "=", " ", 
        RowBox[{"{", "}"}]}], ",", 
       RowBox[{"remainders", " ", "=", " ", 
        RowBox[{"{", "}"}]}]}], "}"}], ",", "\n", 
     RowBox[{
      RowBox[{
       RowBox[{"CountRecurring", "[", 
        RowBox[{"a1_", ",", "b1_"}], "]"}], ":=", 
       RowBox[{"Module", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"devided", ",", "remainder", ",", "quotient"}], "}"}], ",", 
         "\n", "\t", 
         RowBox[{
          RowBox[{"devided", " ", "=", " ", 
           RowBox[{"QuotientRemainder", "[", 
            RowBox[{"a1", ",", "b1"}], "]"}]}], ";", "\n", "\t", 
          RowBox[{"AppendTo", "[", 
           RowBox[{"result", ",", 
            RowBox[{
            "devided", "\[LeftDoubleBracket]", "1", 
             "\[RightDoubleBracket]"}]}], "]"}], ";", "\n", "\t", 
          RowBox[{"If", "[", 
           RowBox[{
            RowBox[{
             RowBox[{"!", 
              RowBox[{"MemberQ", "[", 
               RowBox[{"remainders", ",", 
                RowBox[{
                "devided", "\[LeftDoubleBracket]", "2", 
                 "\[RightDoubleBracket]"}]}], "]"}]}], " ", "&&", " ", 
             RowBox[{
              RowBox[{
              "devided", "\[LeftDoubleBracket]", "2", 
               "\[RightDoubleBracket]"}], "\[NotEqual]", " ", "0"}]}], ",", 
            "\n", "\t", 
            RowBox[{
             RowBox[{"AppendTo", "[", 
              RowBox[{"remainders", ",", 
               RowBox[{
               "devided", "\[LeftDoubleBracket]", "2", 
                "\[RightDoubleBracket]"}]}], "]"}], ";", "\n", "\t ", 
             RowBox[{"CountRecurring", "[", 
              RowBox[{
               RowBox[{
                RowBox[{
                "devided", "\[LeftDoubleBracket]", "2", 
                 "\[RightDoubleBracket]"}], "*", "10"}], ",", "b1"}], "]"}], 
             ";"}]}], "\n", "\t", "]"}], ";"}]}], "\n", "]"}]}], ";", "\n", 
      RowBox[{"CountRecurring", "[", 
       RowBox[{"a", ",", "b"}], "]"}], ";", "\n", 
      RowBox[{"Length", "@", "result"}]}]}], "\n", "]"}]}], ";"}], "\n", 
 RowBox[{"MaximalBy", "[", 
  RowBox[{
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"i", ",", 
       RowBox[{"LegthRecurring", "[", 
        RowBox[{"1", ",", "i"}], "]"}]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{"i", ",", "1000"}], "}"}]}], "]"}], ",", "Last"}], 
  "]"}]}], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}, 
   3.8274409867043624`*^9, {3.827531306180939*^9, 3.8275313491132317`*^9}, {
   3.827532624312795*^9, 3.827532634489795*^9}, {3.8275327236167955`*^9, 
   3.827532741779795*^9}, {3.827532797546795*^9, 3.8275328075507956`*^9}, {
   3.827532856739795*^9, 3.827532885207795*^9}, {3.8275329159157953`*^9, 
   3.8275329176007953`*^9}, {3.827532982344795*^9, 3.827532995296795*^9}, {
   3.827533392897599*^9, 3.8275334231026196`*^9}, {3.827533534769785*^9, 
   3.8275336557778845`*^9}, {3.827533720698376*^9, 3.8275337284861546`*^9}, {
   3.827533854731778*^9, 3.8275339650518093`*^9}, {3.8275341210704093`*^9, 
   3.8275342111834197`*^9}, {3.8275342918144817`*^9, 3.827534313088609*^9}, {
   3.8275343784731474`*^9, 3.8275343877170715`*^9}, {3.82753563672696*^9, 
   3.827535677511038*^9}, {3.8275392981850786`*^9, 3.82753936400266*^9}, {
   3.827542660934329*^9, 3.8275426725004854`*^9}, 3.827542854599694*^9, {
   3.8275431979850287`*^9, 3.8275432845587435`*^9}, {3.8275433163037434`*^9, 
   3.8275434454947433`*^9}, {3.8275435569737434`*^9, 
   3.8275435645627437`*^9}, {3.8275436872737436`*^9, 3.827543701099744*^9}, {
   3.827543963100542*^9, 3.8275439805962915`*^9}, {3.827544034126644*^9, 
   3.827544054020633*^9}, {3.827544305932822*^9, 3.827544306678897*^9}, {
   3.8275443607423024`*^9, 3.8275443835165796`*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"{", 
   RowBox[{"983", ",", "983"}], "}"}], "}"}]], "Output",
 CellChangeTimes->{{3.8275433530257435`*^9, 3.827543387033744*^9}, {
   3.8275434211237435`*^9, 3.8275434470937433`*^9}, 3.827543570948744*^9, {
   3.827543974119644*^9, 3.8275440033855705`*^9}, {3.827544037765008*^9, 
   3.827544057356967*^9}, {3.827544300702299*^9, 3.827544324055634*^9}}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]27. Quadratic primes", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}, {
   3.827440966885229*^9, 3.8274409684953213`*^9}, {3.827552739756134*^9, 
   3.8275527449496536`*^9}}],

Cell[TextData[{
 "Euler discovered the remarkable quadratic formula:",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     SuperscriptBox["n", "2"], "+", "n", "+", "41"}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 "\nIt turns out that the formula will produce 40 primes for the consecutive \
integer values",
 Cell[BoxData[
  FormBox[
   RowBox[{" ", 
    RowBox[{"0", "\[LessEqual]", "n", "\[LessEqual]", "39"}]}], 
   TraditionalForm]]],
 " . However, when",
 Cell[BoxData[
  FormBox[
   RowBox[{" ", 
    TagBox[
     RowBox[{
      RowBox[{"n", "=", "40"}], ",", 
      RowBox[{
       RowBox[{
        SuperscriptBox["40", "2"], "+", "40", "+", "41"}], "=", 
       RowBox[{
        RowBox[{"40", 
         RowBox[{
          StyleBox["(",
           SpanMinSize->1.,
           SpanMaxSize->1.], 
          RowBox[{"40", "+", "1"}], 
          StyleBox[")",
           SpanMinSize->1.,
           SpanMaxSize->1.]}]}], "+", "41"}]}]}],
     "MathMLPresentationTag",
     AutoDelete->True]}], TraditionalForm]], "Input"],
 " is divisible by 41, and certainly when ",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     RowBox[{"n", "=", "41"}], ",", 
     RowBox[{
      SuperscriptBox["41", "2"], "+", "41", "+", "41"}]}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 " is clearly divisible by 41.\nThe incredible formula",
 Cell[BoxData[
  FormBox[
   RowBox[{" ", 
    RowBox[{
     SuperscriptBox["n", "2"], "\[Minus]", 
     RowBox[{"79", "n"}], "+", "1601"}]}], TraditionalForm]]],
 "was discovered, which produces 80 primes for the consecutive values",
 Cell[BoxData[
  FormBox[
   RowBox[{" ", 
    RowBox[{"0", "\[LessEqual]", "n", "\[LessEqual]", "79"}]}], 
   TraditionalForm]]],
 ". The product of the coefficients, \[Minus]79 and 1601, is \[Minus]126479.\n\
Considering quadratics of the form:",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     SuperscriptBox["n", "2"], "+", 
     RowBox[{"a", "n"}], "+", "b"}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 ", where ",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.], "a", 
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.], 
     RowBox[{"<", "1000"}]}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 " and ",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.], "b", 
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.], 
     RowBox[{"\[LessEqual]", "1000"}]}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 "\nwhere",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.], "n", 
     StyleBox["|",
      SpanMinSize->1.,
      SpanMaxSize->1.]}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 "is the modulus/absolute value of n\ne.g. ",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     RowBox[{
      StyleBox["|",
       SpanMinSize->1.,
       SpanMaxSize->1.], "11", 
      StyleBox["|",
       SpanMinSize->1.,
       SpanMaxSize->1.]}], "=", "11"}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 " and ",
 Cell[BoxData[
  FormBox[
   TagBox[
    RowBox[{
     RowBox[{
      StyleBox["|",
       SpanMinSize->1.,
       SpanMaxSize->1.], 
      RowBox[{"\[Minus]", "4"}], 
      StyleBox["|",
       SpanMinSize->1.,
       SpanMaxSize->1.]}], "=", "4"}],
    "MathMLPresentationTag",
    AutoDelete->True], TraditionalForm]]],
 "\nFind the product of the coefficients,a and b , for the quadratic \
expression that produces the maximum number of primes for consecutive values \
of n , starting with n=0."
}], "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}, {
   3.827440974140644*^9, 3.827440983055154*^9}, 3.8275527536655245`*^9, {
   3.827552784182576*^9, 3.827553076006756*^9}, {3.827889420399993*^9, 
   3.827889425315485*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"SequenceLengthQuest", "[", 
    RowBox[{"a_", ",", "b_"}], "]"}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"n", "=", "0"}], "}"}], ",", "\n", "\t", 
     RowBox[{
      RowBox[{"While", "[", 
       RowBox[{
        RowBox[{"PrimeQ", "[", 
         RowBox[{
          SuperscriptBox["n", "2"], "+", 
          RowBox[{"a", "*", "n"}], "+", "b"}], "]"}], ",", 
        RowBox[{
         RowBox[{"n", "++"}], ";"}]}], "]"}], ";", "\n", "\t", "n"}]}], "\n", 
    "]"}]}], ";"}], "\n", 
 RowBox[{"MaximalBy", "[", 
  RowBox[{
   RowBox[{
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"SequenceLengthQuest", "[", 
         RowBox[{"a", ",", "b"}], "]"}], ",", 
        RowBox[{"a", "*", "b"}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"a", ",", 
        RowBox[{"-", "999"}], ",", "999"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"b", ",", 
        RowBox[{"Select", "[", 
         RowBox[{
          RowBox[{"Table", "[", 
           RowBox[{"i", ",", 
            RowBox[{"{", 
             RowBox[{"i", ",", 
              RowBox[{"-", "1000"}], ",", "1000"}], "}"}]}], "]"}], ",", 
          "PrimeQ"}], "]"}]}], "}"}]}], "]"}], "//", 
    RowBox[{
     RowBox[{"Flatten", "[", 
      RowBox[{"#", ",", "1"}], "]"}], "&"}]}], ",", "First"}], "]"}]}], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}, 
   3.8274409867043624`*^9, {3.827531306180939*^9, 3.8275313491132317`*^9}, {
   3.827532624312795*^9, 3.827532634489795*^9}, {3.8275327236167955`*^9, 
   3.827532741779795*^9}, {3.827532797546795*^9, 3.8275328075507956`*^9}, {
   3.827532856739795*^9, 3.827532885207795*^9}, {3.8275329159157953`*^9, 
   3.8275329176007953`*^9}, {3.827532982344795*^9, 3.827532995296795*^9}, {
   3.827533392897599*^9, 3.8275334231026196`*^9}, {3.827533534769785*^9, 
   3.8275336557778845`*^9}, {3.827533720698376*^9, 3.8275337284861546`*^9}, {
   3.827533854731778*^9, 3.8275339650518093`*^9}, {3.8275341210704093`*^9, 
   3.8275342111834197`*^9}, {3.8275342918144817`*^9, 3.827534313088609*^9}, {
   3.8275343784731474`*^9, 3.8275343877170715`*^9}, {3.82753563672696*^9, 
   3.827535677511038*^9}, {3.8275392981850786`*^9, 3.82753936400266*^9}, {
   3.827542660934329*^9, 3.8275426725004854`*^9}, 3.827542854599694*^9, {
   3.8275431979850287`*^9, 3.8275432845587435`*^9}, {3.8275433163037434`*^9, 
   3.8275434454947433`*^9}, {3.8275435569737434`*^9, 
   3.8275435645627437`*^9}, {3.8275436872737436`*^9, 3.827543701099744*^9}, {
   3.827543963100542*^9, 3.8275439805962915`*^9}, {3.827544034126644*^9, 
   3.827544054020633*^9}, {3.827544305932822*^9, 3.827544306678897*^9}, {
   3.8275443607423024`*^9, 3.8275443835165796`*^9}, 3.827888854280387*^9, {
   3.8278895004539976`*^9, 3.827889512707223*^9}, {3.8278897696801176`*^9, 
   3.827889856110118*^9}, {3.827889950702118*^9, 3.827889955254118*^9}, {
   3.82789022665462*^9, 3.8278902772026744`*^9}, {3.827890310414995*^9, 
   3.8278903862375765`*^9}, {3.8278907816051097`*^9, 
   3.8278907824361925`*^9}, {3.8278910225682034`*^9, 3.827891102425188*^9}, {
   3.8278911327072163`*^9, 3.8278911504819937`*^9}, {3.8278911853344784`*^9, 
   3.8278912426802125`*^9}, {3.8278913143843822`*^9, 3.827891357607704*^9}, {
   3.827891464333376*^9, 3.827891503355277*^9}, {3.827891558646806*^9, 
   3.8278915687048116`*^9}, 3.8278917511250515`*^9, {3.8278917894168806`*^9, 
   3.827891790880027*^9}, {3.8278919267156096`*^9, 3.8278920220881453`*^9}, {
   3.8278920567416105`*^9, 3.827892062205157*^9}, {3.827892110801016*^9, 
   3.8278921644913845`*^9}, {3.827892204030338*^9, 3.8278922237043047`*^9}, {
   3.8278925142733593`*^9, 3.827892611025033*^9}, {3.8278927135722866`*^9, 
   3.8278928116800966`*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"{", 
   RowBox[{"71", ",", 
    RowBox[{"-", "59231"}]}], "}"}], "}"}]], "Output",
 CellChangeTimes->{{3.8278902486818223`*^9, 3.8278902782457786`*^9}, 
   3.827891244462391*^9, {3.827891326931637*^9, 3.827891345104454*^9}, 
   3.8278915038193235`*^9, {3.8278915615981007`*^9, 3.8278915696489058`*^9}, 
   3.827891755968536*^9, {3.827891933765314*^9, 3.8278919461945567`*^9}, {
   3.8278919768246193`*^9, 3.827892022684205*^9}, {3.8278921192518606`*^9, 
   3.8278921674666815`*^9}, {3.827892219533888*^9, 3.827892233086243*^9}, 
   3.827892535605492*^9, {3.827892575332464*^9, 3.8278926139753284`*^9}, {
   3.8278927239093204`*^9, 3.827892738625792*^9}, {3.827892769149844*^9, 
   3.827892784449374*^9}, 3.827892823050234*^9}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]28. Number spiral diagonals", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}, {
   3.827440966885229*^9, 3.8274409684953213`*^9}, {3.827552739756134*^9, 
   3.8275527449496536`*^9}, {3.8278928750254307`*^9, 3.827892882549183*^9}}],

Cell[TextData[{
 "Starting with the number 1 and moving to the right in a clockwise direction \
a 5 by 5 spiral is formed as follows:\n",
 StyleBox["21",
  FontColor->RGBColor[1, 0, 0]],
 " 22  23 24  ",
 StyleBox["25",
  FontColor->RGBColor[1, 0, 0]],
 "\n20 ",
 StyleBox[" 7",
  FontColor->RGBColor[1, 0, 0]],
 " ",
 StyleBox["  ",
  FontColor->RGBColor[1, 0, 0]],
 StyleBox["8   ",
  FontColor->GrayLevel[0]],
 StyleBox["9",
  FontColor->RGBColor[1, 0, 0]],
 "   10\n19  6   ",
 StyleBox["1",
  FontColor->RGBColor[1, 0, 0]],
 "   2   11\n18  ",
 StyleBox["5",
  FontColor->RGBColor[1, 0, 0]],
 "   4   ",
 StyleBox["3",
  FontColor->RGBColor[1, 0, 0]],
 "   12\n",
 StyleBox["17",
  FontColor->RGBColor[1, 0, 0]],
 " 16  15 14",
 StyleBox["  13",
  FontColor->RGBColor[1, 0, 0]],
 "\nIt can be verified that the sum of the numbers on the diagonals is 101.\n\
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral \
formed in the same way?"
}], "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}, {
   3.827440974140644*^9, 3.827440983055154*^9}, 3.8275527536655245`*^9, {
   3.827552784182576*^9, 3.827553076006756*^9}, {3.827889420399993*^9, 
   3.827889425315485*^9}, {3.827892889027831*^9, 3.8278928990668344`*^9}, {
   3.8278929700829353`*^9, 3.82789297043097*^9}, {3.827893009783905*^9, 
   3.8278930269986267`*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"No28", "[", "n_", "]"}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       RowBox[{"sum", "=", "1"}], ",", "temp", ",", "i"}], "}"}], ",", "\n", 
     RowBox[{
      RowBox[{"For", "[", 
       RowBox[{
        RowBox[{"i", "=", "2"}], ",", 
        RowBox[{"i", "\[LessEqual]", 
         RowBox[{
          RowBox[{"Quotient", "[", 
           RowBox[{"n", ",", "2"}], "]"}], "+", "1"}]}], ",", 
        RowBox[{"i", "++"}], ",", "\n", "\t", 
        RowBox[{"sum", "+=", 
         RowBox[{"16", "-", 
          RowBox[{"28", " ", "i"}], "+", 
          RowBox[{"16", " ", 
           SuperscriptBox["i", "2"]}]}]}]}], " ", 
       RowBox[{
       "(*", "\:7531\:7b49\:5dee\:6570\:5217\:8ba1\:7b97\:8fc7\:7a0b\:5316\
\:7b80\:6765", "*)"}], "\n", "]"}], ";", "\n", "sum"}]}], "]"}]}], 
  ";"}], "\n", 
 RowBox[{"No28", "[", "1001", "]"}]}], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}, 
   3.8274409867043624`*^9, {3.827531306180939*^9, 3.8275313491132317`*^9}, {
   3.827532624312795*^9, 3.827532634489795*^9}, {3.8275327236167955`*^9, 
   3.827532741779795*^9}, {3.827532797546795*^9, 3.8275328075507956`*^9}, {
   3.827532856739795*^9, 3.827532885207795*^9}, {3.8275329159157953`*^9, 
   3.8275329176007953`*^9}, {3.827532982344795*^9, 3.827532995296795*^9}, {
   3.827533392897599*^9, 3.8275334231026196`*^9}, {3.827533534769785*^9, 
   3.8275336557778845`*^9}, {3.827533720698376*^9, 3.8275337284861546`*^9}, {
   3.827533854731778*^9, 3.8275339650518093`*^9}, {3.8275341210704093`*^9, 
   3.8275342111834197`*^9}, {3.8275342918144817`*^9, 3.827534313088609*^9}, {
   3.8275343784731474`*^9, 3.8275343877170715`*^9}, {3.82753563672696*^9, 
   3.827535677511038*^9}, {3.8275392981850786`*^9, 3.82753936400266*^9}, {
   3.827542660934329*^9, 3.8275426725004854`*^9}, 3.827542854599694*^9, {
   3.8275431979850287`*^9, 3.8275432845587435`*^9}, {3.8275433163037434`*^9, 
   3.8275434454947433`*^9}, {3.8275435569737434`*^9, 
   3.8275435645627437`*^9}, {3.8275436872737436`*^9, 3.827543701099744*^9}, {
   3.827543963100542*^9, 3.8275439805962915`*^9}, {3.827544034126644*^9, 
   3.827544054020633*^9}, {3.827544305932822*^9, 3.827544306678897*^9}, {
   3.8275443607423024`*^9, 3.8275443835165796`*^9}, 3.827888854280387*^9, {
   3.8278895004539976`*^9, 3.827889512707223*^9}, {3.8278897696801176`*^9, 
   3.827889856110118*^9}, {3.827889950702118*^9, 3.827889955254118*^9}, {
   3.82789022665462*^9, 3.8278902772026744`*^9}, {3.827890310414995*^9, 
   3.8278903862375765`*^9}, {3.8278907816051097`*^9, 
   3.8278907824361925`*^9}, {3.8278910225682034`*^9, 3.827891102425188*^9}, {
   3.8278911327072163`*^9, 3.8278911504819937`*^9}, {3.8278911853344784`*^9, 
   3.8278912426802125`*^9}, {3.8278913143843822`*^9, 3.827891357607704*^9}, {
   3.827891464333376*^9, 3.827891503355277*^9}, {3.827891558646806*^9, 
   3.8278915687048116`*^9}, 3.8278917511250515`*^9, {3.8278917894168806`*^9, 
   3.827891790880027*^9}, {3.8278919267156096`*^9, 3.8278920220881453`*^9}, {
   3.8278920567416105`*^9, 3.827892062205157*^9}, {3.827892110801016*^9, 
   3.8278921644913845`*^9}, {3.827892204030338*^9, 3.8278922237043047`*^9}, {
   3.8278925142733593`*^9, 3.827892611025033*^9}, {3.8278927135722866`*^9, 
   3.8278928116800966`*^9}, 3.8278930347774043`*^9, {3.82789359854678*^9, 
   3.8278936023661623`*^9}, {3.827894517892706*^9, 3.8278945692878447`*^9}, {
   3.827894604251341*^9, 3.827894640128928*^9}, {3.8278958365535583`*^9, 
   3.8278958499879017`*^9}, {3.827895888666769*^9, 3.827895972768179*^9}, {
   3.827896024572358*^9, 3.827896163953295*^9}, {3.827896884571083*^9, 
   3.827896967008083*^9}, {3.827897112746083*^9, 3.8278971407630825`*^9}, {
   3.827897218979083*^9, 3.827897219305083*^9}, {3.827897324557083*^9, 
   3.827897333686083*^9}, {3.8278973684440827`*^9, 3.8278974139192886`*^9}}],

Cell[BoxData["669171001"], "Output",
 CellChangeTimes->{
  3.8278960801079116`*^9, {3.827896133682268*^9, 3.82789616640354*^9}, 
   3.8278968963550825`*^9, {3.8278969479770827`*^9, 3.827896967659083*^9}, {
   3.8278971970690827`*^9, 3.827897238856083*^9}, {3.827897334949083*^9, 
   3.8278973359470825`*^9}, {3.8278973964935465`*^9, 3.827897414525349*^9}}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]29. Distinct powers", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}, {
   3.827440966885229*^9, 3.8274409684953213`*^9}, {3.827552739756134*^9, 
   3.8275527449496536`*^9}, {3.8278928750254307`*^9, 3.827892882549183*^9}, {
   3.827897246606083*^9, 3.827897252439083*^9}}],

Cell[TextData[{
 "Consider all integer combinations of ab for 2 \[LessEqual] a \[LessEqual] 5 \
and 2 \[LessEqual] b \[LessEqual] 5:\n    ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["2", "2"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=4, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["2", "3"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=8, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["2", "4"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=16, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["2", "5"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=32\n    ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["3", "2"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=9, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["3", "3"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=27, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["3", "4"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=81, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["3", "5"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=243\n    ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["4", "2"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=16, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["4", "3"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=64, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["4", "4"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=256, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["4", "5"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=1024\n    ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["5", "2"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=25, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["5", "3"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=125, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["5", "4"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=625, ",
 Cell[BoxData[
  FormBox[
   SuperscriptBox["5", "5"], TraditionalForm]],
  FormatType->"TraditionalForm"],
 "=3125\nIf they are then placed in numerical order, with any repeats \
removed, we get the following sequence of 15 distinct terms:\n4, 8, 9, 16, \
25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125\nHow many distinct terms \
are in the sequence generated by ab for 2 \[LessEqual] a \[LessEqual] 100 and \
2 \[LessEqual] b \[LessEqual] 100?"
}], "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}, {
   3.827440974140644*^9, 3.827440983055154*^9}, 3.8275527536655245`*^9, {
   3.827552784182576*^9, 3.827553076006756*^9}, {3.827889420399993*^9, 
   3.827889425315485*^9}, {3.827892889027831*^9, 3.8278928990668344`*^9}, {
   3.8278929700829353`*^9, 3.82789297043097*^9}, {3.827893009783905*^9, 
   3.8278930269986267`*^9}, {3.8278972577940826`*^9, 
   3.8278972637090826`*^9}, {3.8286660411523495`*^9, 3.828666144243657*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"Table", "[", 
     RowBox[{
      SuperscriptBox["a", "b"], ",", 
      RowBox[{"{", 
       RowBox[{"a", ",", "2", ",", "100"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"b", ",", "2", ",", "100"}], "}"}]}], "]"}], "//", "Flatten"}],
    "//", "DeleteDuplicates"}], "//", "Length"}]], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}, 
   3.8274409867043624`*^9, {3.827531306180939*^9, 3.8275313491132317`*^9}, {
   3.827532624312795*^9, 3.827532634489795*^9}, {3.8275327236167955`*^9, 
   3.827532741779795*^9}, {3.827532797546795*^9, 3.8275328075507956`*^9}, {
   3.827532856739795*^9, 3.827532885207795*^9}, {3.8275329159157953`*^9, 
   3.8275329176007953`*^9}, {3.827532982344795*^9, 3.827532995296795*^9}, {
   3.827533392897599*^9, 3.8275334231026196`*^9}, {3.827533534769785*^9, 
   3.8275336557778845`*^9}, {3.827533720698376*^9, 3.8275337284861546`*^9}, {
   3.827533854731778*^9, 3.8275339650518093`*^9}, {3.8275341210704093`*^9, 
   3.8275342111834197`*^9}, {3.8275342918144817`*^9, 3.827534313088609*^9}, {
   3.8275343784731474`*^9, 3.8275343877170715`*^9}, {3.82753563672696*^9, 
   3.827535677511038*^9}, {3.8275392981850786`*^9, 3.82753936400266*^9}, {
   3.827542660934329*^9, 3.8275426725004854`*^9}, 3.827542854599694*^9, {
   3.8275431979850287`*^9, 3.8275432845587435`*^9}, {3.8275433163037434`*^9, 
   3.8275434454947433`*^9}, {3.8275435569737434`*^9, 
   3.8275435645627437`*^9}, {3.8275436872737436`*^9, 3.827543701099744*^9}, {
   3.827543963100542*^9, 3.8275439805962915`*^9}, {3.827544034126644*^9, 
   3.827544054020633*^9}, {3.827544305932822*^9, 3.827544306678897*^9}, {
   3.8275443607423024`*^9, 3.8275443835165796`*^9}, 3.827888854280387*^9, {
   3.8278895004539976`*^9, 3.827889512707223*^9}, {3.8278897696801176`*^9, 
   3.827889856110118*^9}, {3.827889950702118*^9, 3.827889955254118*^9}, {
   3.82789022665462*^9, 3.8278902772026744`*^9}, {3.827890310414995*^9, 
   3.8278903862375765`*^9}, {3.8278907816051097`*^9, 
   3.8278907824361925`*^9}, {3.8278910225682034`*^9, 3.827891102425188*^9}, {
   3.8278911327072163`*^9, 3.8278911504819937`*^9}, {3.8278911853344784`*^9, 
   3.8278912426802125`*^9}, {3.8278913143843822`*^9, 3.827891357607704*^9}, {
   3.827891464333376*^9, 3.827891503355277*^9}, {3.827891558646806*^9, 
   3.8278915687048116`*^9}, 3.8278917511250515`*^9, {3.8278917894168806`*^9, 
   3.827891790880027*^9}, {3.8278919267156096`*^9, 3.8278920220881453`*^9}, {
   3.8278920567416105`*^9, 3.827892062205157*^9}, {3.827892110801016*^9, 
   3.8278921644913845`*^9}, {3.827892204030338*^9, 3.8278922237043047`*^9}, {
   3.8278925142733593`*^9, 3.827892611025033*^9}, {3.8278927135722866`*^9, 
   3.8278928116800966`*^9}, 3.8278930347774043`*^9, {3.82789359854678*^9, 
   3.8278936023661623`*^9}, {3.827894517892706*^9, 3.8278945692878447`*^9}, {
   3.827894604251341*^9, 3.827894640128928*^9}, {3.8278958365535583`*^9, 
   3.8278958499879017`*^9}, {3.827895888666769*^9, 3.827895972768179*^9}, {
   3.827896024572358*^9, 3.827896163953295*^9}, {3.827896884571083*^9, 
   3.827896967008083*^9}, {3.827897112746083*^9, 3.8278971407630825`*^9}, {
   3.827897218979083*^9, 3.827897219305083*^9}, 3.827897265755083*^9, {
   3.8286661801612487`*^9, 3.828666328841115*^9}}],

Cell[BoxData["9183"], "Output",
 CellChangeTimes->{{3.828666218040036*^9, 3.828666250452277*^9}, {
  3.828666281606392*^9, 3.828666329361167*^9}}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["\[FilledSquare]30. Digit fifth powers", "Subsubsection",
 CellChangeTimes->{
  3.82580077140097*^9, {3.825995270185877*^9, 3.8259952717480335`*^9}, 
   3.82599530340602*^9, {3.826938060773159*^9, 3.8269380691819997`*^9}, {
   3.8269441298000193`*^9, 3.8269441398180213`*^9}, {3.8274402075948*^9, 
   3.8274402093499002`*^9}, {3.827440672901414*^9, 3.8274406852871227`*^9}, {
   3.827440966885229*^9, 3.8274409684953213`*^9}, {3.827552739756134*^9, 
   3.8275527449496536`*^9}, {3.8278928750254307`*^9, 3.827892882549183*^9}, {
   3.827897246606083*^9, 3.827897252439083*^9}, {3.828666374761707*^9, 
   3.828666376884919*^9}}],

Cell[TextData[{
 "Surprisingly there are only three numbers that can be written as the sum of \
fourth powers of their digits:\n    1634 = ",
 Cell[BoxData[
  RowBox[{
   SuperscriptBox["1", "4"], "+", 
   SuperscriptBox["6", "4"], "+", 
   SuperscriptBox["3", "4"], "+", 
   SuperscriptBox["4", "4"]}]], "Output",
  CellChangeTimes->{{3.82866648610684*^9, 3.8286665384670753`*^9}}],
 "\n    8208 = ",
 Cell[BoxData[
  RowBox[{
   SuperscriptBox["8", "4"], "+", 
   SuperscriptBox["2", "4"], "+", 
   SuperscriptBox["0", "4"], "+", 
   SuperscriptBox["8", "4"]}]], "Output",
  CellChangeTimes->{{3.82866648610684*^9, 3.8286665163838673`*^9}}],
 "\n    9474 = ",
 Cell[BoxData[
  RowBox[{
   SuperscriptBox["9", "4"], "+", 
   SuperscriptBox["4", "4"], "+", 
   SuperscriptBox["7", "4"], "+", 
   SuperscriptBox["4", "4"]}]], "Output",
  CellChangeTimes->{{3.82866648610684*^9, 3.8286665281000395`*^9}}],
 "\nAs 1 = 14 is not a sum it is not included.The sum of these numbers is \
1634 + 8208 + 9474 = 19316.\nFind the sum of all the numbers that can be \
written as the sum of fifth powers of their digits."
}], "Text",
 CellChangeTimes->{
  3.825800785096339*^9, {3.8259952767425327`*^9, 3.82599530340602*^9}, {
   3.826938082976379*^9, 3.826938089659047*^9}, 3.8269381234964304`*^9, {
   3.826944143361376*^9, 3.8269441495229917`*^9}, {3.827440214923219*^9, 
   3.82744022000451*^9}, {3.827440672901414*^9, 3.8274407022400923`*^9}, {
   3.827440974140644*^9, 3.827440983055154*^9}, 3.8275527536655245`*^9, {
   3.827552784182576*^9, 3.827553076006756*^9}, {3.827889420399993*^9, 
   3.827889425315485*^9}, {3.827892889027831*^9, 3.8278928990668344`*^9}, {
   3.8278929700829353`*^9, 3.82789297043097*^9}, {3.827893009783905*^9, 
   3.8278930269986267`*^9}, {3.8278972577940826`*^9, 
   3.8278972637090826`*^9}, {3.8286660411523495`*^9, 3.828666144243657*^9}, {
   3.8286663817704077`*^9, 3.8286664424464746`*^9}, {3.828666523055535*^9, 
   3.8286665450917377`*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{"returns", " ", "bool"}], "*)"}], "\n", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"No30", "[", "n_", "]"}], ":=", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", "}"}], ",", "\n", "\t", 
       RowBox[{
        RowBox[{"(", 
         RowBox[{
          RowBox[{
           RowBox[{
            RowBox[{"Power", "[", 
             RowBox[{"#", ",", "5"}], "]"}], "&"}], " ", "@", " ", 
           RowBox[{"IntegerDigits", "[", "n", "]"}]}], "//", "Total"}], ")"}],
         "\[Equal]", "n"}]}], "\n", "]"}]}], ";"}], "\n", 
   RowBox[{
   "(*", "\:4e3a\:4ec0\:4e486\:4f4d\:6570\:4ee5\:4e0a\:5c31\:6ca1\:6709\:7b26\
\:5408\:6761\:4ef6\:7684\:4e86\:6709\:5f85\:786e\:8ba4", "*)"}], "\n", 
   RowBox[{
    RowBox[{"Select", "[", 
     RowBox[{
      RowBox[{"Range", "[", 
       RowBox[{"2", ",", "999999"}], "]"}], ",", "No30"}], "]"}], "//", 
    "Total"}]}]}]], "Code",
 CellChangeTimes->{{3.8258008038272123`*^9, 3.8258008082036495`*^9}, 
   3.82599530340702*^9, 3.82599537860802*^9, {3.826926436526827*^9, 
   3.826926621795352*^9}, {3.8269266541365857`*^9, 3.8269266892090926`*^9}, {
   3.8269268145986304`*^9, 3.8269270607342415`*^9}, {3.826928299701293*^9, 
   3.8269283428202934`*^9}, 3.826928506205293*^9, {3.8269286833582935`*^9, 
   3.8269286845422935`*^9}, {3.8269287505802183`*^9, 3.826928837364896*^9}, {
   3.826928878735033*^9, 3.8269289242895875`*^9}, {3.826929187917948*^9, 
   3.8269291900451603`*^9}, {3.8269335712342405`*^9, 3.826933579920109*^9}, {
   3.8269342002451353`*^9, 3.8269342948795977`*^9}, {3.826934453994508*^9, 
   3.826934484802588*^9}, {3.8269345278018875`*^9, 3.8269346025363607`*^9}, {
   3.8269349797030735`*^9, 3.8269350310402064`*^9}, {3.8269351190500064`*^9, 
   3.826935152429344*^9}, {3.82693522929703*^9, 3.8269352573768377`*^9}, {
   3.8269353290802565`*^9, 3.8269353642912564`*^9}, {3.8269358955142565`*^9, 
   3.826935922493352*^9}, {3.8269362234794474`*^9, 3.82693623760286*^9}, {
   3.826936542273324*^9, 3.826936603461442*^9}, 3.826936663876483*^9, 
   3.8269371195460453`*^9, 3.826937420671155*^9, {3.826937498571944*^9, 
   3.826937542254312*^9}, {3.826937624536539*^9, 3.82693762894298*^9}, {
   3.8269376778298683`*^9, 3.82693770204729*^9}, {3.826937807974881*^9, 
   3.8269378122343073`*^9}, {3.826937932014284*^9, 3.826937949174*^9}, 
   3.8269380926043415`*^9, {3.8269381346355443`*^9, 3.826938156217702*^9}, {
   3.8269382828923683`*^9, 3.8269383238324623`*^9}, {3.8269383686929474`*^9, 
   3.82693838251433*^9}, {3.826938432841362*^9, 3.82693843582666*^9}, {
   3.826938675110586*^9, 3.826938678808956*^9}, 3.8269387175358286`*^9, {
   3.8269387802951035`*^9, 3.8269387999830723`*^9}, {3.8269421165807085`*^9, 
   3.826942178716921*^9}, {3.8269425372112217`*^9, 3.826942580771222*^9}, {
   3.826943545140559*^9, 3.8269436119692416`*^9}, {3.8269437890619493`*^9, 
   3.826943793092352*^9}, {3.826943836085651*^9, 3.8269439065897007`*^9}, {
   3.8269439716722083`*^9, 3.8269440322662673`*^9}, 3.826944152937333*^9, {
   3.827440365558835*^9, 3.827440372308221*^9}, {3.8274404311415863`*^9, 
   3.827440509898091*^9}, 3.8274406729024143`*^9, {3.8274407078004103`*^9, 
   3.8274407086984615`*^9}, {3.8274408189667683`*^9, 3.827440928513034*^9}, 
   3.8274409867043624`*^9, {3.827531306180939*^9, 3.8275313491132317`*^9}, {
   3.827532624312795*^9, 3.827532634489795*^9}, {3.8275327236167955`*^9, 
   3.827532741779795*^9}, {3.827532797546795*^9, 3.8275328075507956`*^9}, {
   3.827532856739795*^9, 3.827532885207795*^9}, {3.8275329159157953`*^9, 
   3.8275329176007953`*^9}, {3.827532982344795*^9, 3.827532995296795*^9}, {
   3.827533392897599*^9, 3.8275334231026196`*^9}, {3.827533534769785*^9, 
   3.8275336557778845`*^9}, {3.827533720698376*^9, 3.8275337284861546`*^9}, {
   3.827533854731778*^9, 3.8275339650518093`*^9}, {3.8275341210704093`*^9, 
   3.8275342111834197`*^9}, {3.8275342918144817`*^9, 3.827534313088609*^9}, {
   3.8275343784731474`*^9, 3.8275343877170715`*^9}, {3.82753563672696*^9, 
   3.827535677511038*^9}, {3.8275392981850786`*^9, 3.82753936400266*^9}, {
   3.827542660934329*^9, 3.8275426725004854`*^9}, 3.827542854599694*^9, {
   3.8275431979850287`*^9, 3.8275432845587435`*^9}, {3.8275433163037434`*^9, 
   3.8275434454947433`*^9}, {3.8275435569737434`*^9, 
   3.8275435645627437`*^9}, {3.8275436872737436`*^9, 3.827543701099744*^9}, {
   3.827543963100542*^9, 3.8275439805962915`*^9}, {3.827544034126644*^9, 
   3.827544054020633*^9}, {3.827544305932822*^9, 3.827544306678897*^9}, {
   3.8275443607423024`*^9, 3.8275443835165796`*^9}, 3.827888854280387*^9, {
   3.8278895004539976`*^9, 3.827889512707223*^9}, {3.8278897696801176`*^9, 
   3.827889856110118*^9}, {3.827889950702118*^9, 3.827889955254118*^9}, {
   3.82789022665462*^9, 3.8278902772026744`*^9}, {3.827890310414995*^9, 
   3.8278903862375765`*^9}, {3.8278907816051097`*^9, 
   3.8278907824361925`*^9}, {3.8278910225682034`*^9, 3.827891102425188*^9}, {
   3.8278911327072163`*^9, 3.8278911504819937`*^9}, {3.8278911853344784`*^9, 
   3.8278912426802125`*^9}, {3.8278913143843822`*^9, 3.827891357607704*^9}, {
   3.827891464333376*^9, 3.827891503355277*^9}, {3.827891558646806*^9, 
   3.8278915687048116`*^9}, 3.8278917511250515`*^9, {3.8278917894168806`*^9, 
   3.827891790880027*^9}, {3.8278919267156096`*^9, 3.8278920220881453`*^9}, {
   3.8278920567416105`*^9, 3.827892062205157*^9}, {3.827892110801016*^9, 
   3.8278921644913845`*^9}, {3.827892204030338*^9, 3.8278922237043047`*^9}, {
   3.8278925142733593`*^9, 3.827892611025033*^9}, {3.8278927135722866`*^9, 
   3.8278928116800966`*^9}, 3.8278930347774043`*^9, {3.82789359854678*^9, 
   3.8278936023661623`*^9}, {3.827894517892706*^9, 3.8278945692878447`*^9}, {
   3.827894604251341*^9, 3.827894640128928*^9}, {3.8278958365535583`*^9, 
   3.8278958499879017`*^9}, {3.827895888666769*^9, 3.827895972768179*^9}, {
   3.827896024572358*^9, 3.827896163953295*^9}, {3.827896884571083*^9, 
   3.827896967008083*^9}, {3.827897112746083*^9, 3.8278971407630825`*^9}, {
   3.827897218979083*^9, 3.827897219305083*^9}, 3.827897265755083*^9, {
   3.8286661801612487`*^9, 3.828666328841115*^9}, 3.8286664043966703`*^9, {
   3.8286666030015287`*^9, 3.828666636046833*^9}, {3.828666840459272*^9, 
   3.8286669574119663`*^9}, {3.828666989241149*^9, 3.8286670178870125`*^9}, {
   3.828667053025526*^9, 3.828667347779999*^9}, {3.8286675065138707`*^9, 
   3.8286675415063696`*^9}}],

Cell[BoxData["443839"], "Output",
 CellChangeTimes->{{3.8286671471179347`*^9, 3.8286671629475174`*^9}, {
  3.828667213795602*^9, 3.8286672517113934`*^9}, {3.8286672857988014`*^9, 
  3.8286673550667276`*^9}}]
}, Open  ]]
}, Open  ]]
}, Open  ]]
},
WindowToolbars->"EditBar",
WindowSize->{1600, 826},
WindowMargins->{{-8, Automatic}, {Automatic, -8}},
SpellingDictionaries->{"CorrectWords"->{"Fn"}},
Magnification:>1.3 Inherited,
FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (2016\:5e7410\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[580, 22, 173, 3, 117, "Title"],
Cell[CellGroupData[{
Cell[778, 29, 232, 4, 43, "Subsubsection",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[1013, 35, 654, 12, 114, "Text",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[1670, 49, 2731, 57, 258, "Code",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}]
}, Open  ]],
Cell[4416, 109, 526, 8, 39, "Output"],
Cell[CellGroupData[{
Cell[4967, 121, 276, 4, 43, "Subsubsection",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[5246, 127, 853, 14, 139, "Text",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[6102, 143, 2889, 53, 90, "Code",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}]
}, Open  ]],
Cell[9006, 199, 128, 2, 39, "Output"],
Cell[CellGroupData[{
Cell[9159, 205, 302, 4, 43, "Subsubsection"],
Cell[9464, 211, 1218, 19, 189, "Text"],
Cell[10685, 232, 2154, 29, 65, "Code"]
}, Open  ]],
Cell[CellGroupData[{
Cell[12876, 266, 361, 5, 43, "Subsubsection"],
Cell[13240, 273, 727, 13, 114, "Text"],
Cell[CellGroupData[{
Cell[13992, 290, 2509, 37, 65, "Code"],
Cell[16504, 329, 301, 6, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[16854, 341, 388, 5, 43, "Subsubsection"],
Cell[17245, 348, 784, 24, 438, "Text"],
Cell[CellGroupData[{
Cell[18054, 376, 2464, 35, 65, "Code"],
Cell[20521, 413, 99, 1, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[20669, 420, 430, 6, 43, "Subsubsection"],
Cell[21102, 428, 927, 22, 313, "Text"],
Cell[CellGroupData[{
Cell[22054, 454, 6474, 124, 378, "Code"],
Cell[28531, 580, 393, 7, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[28973, 593, 481, 7, 43, "Subsubsection"],
Cell[29457, 602, 4317, 152, 232, "Text"],
Cell[CellGroupData[{
Cell[33799, 758, 6076, 107, 169, "Code"],
Cell[39878, 867, 766, 13, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[40693, 886, 536, 7, 43, "Subsubsection"],
Cell[41232, 895, 1614, 46, 214, "Text"],
Cell[CellGroupData[{
Cell[42871, 945, 6173, 97, 196, "Code"],
Cell[49047, 1044, 356, 5, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[49452, 1055, 578, 8, 43, "Subsubsection"],
Cell[50033, 1065, 3130, 98, 222, "Text"],
Cell[CellGroupData[{
Cell[53188, 1167, 5573, 81, 68, "Code"],
Cell[58764, 1250, 146, 2, 39, "Output"]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[58959, 1258, 631, 9, 43, "Subsubsection"],
Cell[59593, 1269, 1967, 42, 164, "Text"],
Cell[CellGroupData[{
Cell[61585, 1315, 6439, 102, 186, "Code"],
Cell[68027, 1419, 207, 3, 39, "Output"]
}, Open  ]]
}, Open  ]]
}, Open  ]]
}
]
*)

